
#ifndef __INPUT_H__
#define __INPUT_H__

#include <dinput.h>
#include <string>
#include "TEDefs.h"

using namespace std;

class Input
{
public:

	// Constructor
	Input();

	// Destructor
	~Input();

	// Initialize devices
	bool Initialize(HWND window);

	// Scan the devices & update the buffers
	void UpdateDevices();

	// Acquires the devices for input
	void AcquireDevices();

	// Returns true if a key is pressed
	bool KeyPressed(uchar key) const;
	bool Prev_KeyPressed(uchar key) const;
	bool KeyHeld(uchar key) const; // current & previous state true
	bool KeyPressedOnce(uchar key) const; // current state true & previous state false
	bool KeyReleased(uchar key) const; // current state false & previous state true

	// Mouse Movements
	long MouseX() const { return mouseBuffer.lX; }
	long MouseY() const { return mouseBuffer.lY; }
	long MouseZ() const { return mouseBuffer.lZ; }

	// Mouse Buttons
	bool LeftButton()   const { return (mouseBuffer.rgbButtons[0] & 0x80) != 0; }
	bool RightButton()  const { return (mouseBuffer.rgbButtons[1] & 0x80) != 0; }
	bool MiddleButton() const { return (mouseBuffer.rgbButtons[2] & 0x80) != 0; }

	// Gets some text and adds it to the string
	void GetText(string &str, ushort minSize = 0);

private:

	// DirectInput
	LPDIRECTINPUT8       inputManager; 
	LPDIRECTINPUTDEVICE8 keyboard; 
	LPDIRECTINPUTDEVICE8 mouse; 

	// Current State Buffers
	uchar keyBuffer[256];
	DIMOUSESTATE2 mouseBuffer; 
	//Real3 mouseCoord;

	// Previous State Buffers
	uchar keyBuffer_p[256];
	DIMOUSESTATE2 mouseBuffer_p; 

	// Scans the keyboard keys
	void ScanKeyboard();

	// Scans the mouse
	void ScanMouse();
};

extern Input input;

#endif // __INPUT_H__
